/*
 * Termometer.c
 *
 * Created: 09/03/2012 8:57:24
 *  Author: Javier
 */ 

#include "Termometer.h"
#include "I2C.h"

#define TERMOMETER_ADDR_R 0b10010001
#define TERMOMETER_ADDR_W 0b10010000



//
//
//
uint16_t Temp_Read()
{
	uint8_t addr=TERMOMETER_ADDR_R + (TERMOMETER_ADDR << 1 );
	uint16_t aux=0;
	
	I2C_start();

	// Write Address
	I2C_write(addr);

	// First byte
	// int part (B8~B1)
	aux=I2C_read(1);
	aux=aux << 1;

	// Second Byte
	// Float part
	// if B7==0 => aux[0]=0 else aux[0]=1
	aux+=( I2C_read(0) & 0x80 ) >> 7;
	
	
	I2C_stop();
  
	return aux;
}